package cn.com.idmy.auth.context;


import cn.com.idmy.auth.cookie.Cookie;
import cn.com.idmy.base.model.NameValue;
import org.jetbrains.annotations.NotNull;

import java.util.Collection;

public interface Response {
    String ACCESS_CONTROL_EXPOSE_HEADERS = "Access-Control-Expose-Headers";

    @NotNull Object source();

    default void deleteCookie(@NotNull String name) {
        addCookie(name, null, null, null, 0);
    }

    default void deleteCookie(@NotNull String name, String path, String domain) {
        addCookie(name, null, path, domain, 0);
    }

    default void addCookie(@NotNull String name, String value, String path, String domain, long exp) {
        addCookie(new Cookie().name(name).value(value).path(path).domain(domain).maxAge(exp));
    }

    default void addCookie(@NotNull Cookie cookie) {
        addHeader(Cookie.HEADER_NAME, cookie.toString());
    }

    @NotNull Response status(int status);

    @NotNull Response setHeader(@NotNull String name, @NotNull String value);

    @NotNull Response addHeader(@NotNull String name, @NotNull String value);

    default @NotNull Response setServer(@NotNull String value) {
        return setHeader("Server", value);
    }

    void redirect(@NotNull String url);

    @NotNull Collection<String> headerNames();

    @NotNull Collection<String> headerValues();

    @NotNull Collection<NameValue<String>> headers();
}